package edu.mse.camel.client.events.peer;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

import edu.mse.camel.client.events.AbstractEvent;
import edu.mse.camel.client.events.EventIDs;
import edu.mse.camel.client.events.IEvent;

public class SendGenericPeerEvent extends AbstractEvent implements IEvent{

	private String specificEventId;
	private String dataType;
	private byte [] data;
	
	public <T> boolean writeObject(T entity) {
		try {
			ByteArrayOutputStream b = new ByteArrayOutputStream();
			ObjectOutputStream out;
			out = new ObjectOutputStream(b);
			out.writeObject(entity);
			data = b.toByteArray();
			dataType = entity.getClass().getCanonicalName();
			return true;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
	}

	@Override
	public String getEventID() {
		return EventIDs.SEND_PEER_EVENT;
	}

	public String getDataType() {
		return dataType;
	}

	public byte[] getData() {
		return data;
	}

	public String getSpecificEventId() {
		return specificEventId;
	}

	public void setSpecificEventId(String specificEventId) {
		this.specificEventId = specificEventId;
	}

}
